//
//  OrderFootView.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/21.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "OrderFootView.h"

@implementation OrderFootView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        //self.backgroundColor = TotalWhite;
        [self setView];
    }
    return self;
}

- (void)setView
{
    if (!self.addressView) {
        self.addressView = [UIView new];
        self.addressView.backgroundColor = UIColorFromHex(0xFAFAFA);
        [self addSubview:self.addressView];
    }
    if (!self.addIV) {
        self.addIV = [UIImageView new];
        self.addIV.image = [UIImage imageNamed:@"address"];
        [self.addressView addSubview:self.addIV];
    }
    if (!self.addressLab) {
        self.addressLab = [UILabel new];
        self.addressLab.textColor = UIColorFromHex(0x999999);
        self.addressLab.font = FontMediumWithSize(12);
        NSString *content = @"陈典军，1885486262，杭州市拱墅区莫干山路103号大塘新村612室";
        self.addressLab.text = content;
        self.addressLab.numberOfLines = 0;
        [self.addressView addSubview:self.addressLab];
    }
    if (!self.bottomView) {
        self.bottomView = [UIView new];
        self.bottomView.backgroundColor = TotalWhite;
        [self addSubview:self.bottomView];
        
        CGFloat padding = (SCREENWIDTH-30-36-83)/2;
        NSArray *imageArray = @[@"orderMoney",@"goodsMoney",@"profitMoney"];
        NSArray *titleArray = @[@"订单金额",@"货款金额",@"收益金额"];
        NSArray *desArray = @[@"¥396",@"¥300",@"¥96"];
        for (int i = 0; i < 3; i++) {
            UIImageView *imageV = [UIImageView new];
            imageV.frame = CGRectMake(30+(padding+12)*i, 15, 12, 12);
            imageV.backgroundColor = ClearColor;
            imageV.image = [UIImage imageNamed:imageArray[i]];
            [self.bottomView addSubview:imageV];
            
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(imageV.right+5, imageV.top, 48, 12)];
            label.textColor = UIColorFromHex(0x7777777);
            label.font = FontWithSize(12);
            label.text = titleArray[i];
            [self.bottomView addSubview:label];
            
            UILabel *desLabel = [[UILabel alloc]initWithFrame:CGRectMake(label.left, label.bottom+8, 80, 14)];
            desLabel.tag = 90+i;
            desLabel.textColor = titleColor;
            desLabel.font = [UIFont systemFontOfSize:14];
            desLabel.text = desArray[i];
            [self.bottomView addSubview:desLabel];
            if (i == 0) {
                self.orderIV = imageV;
                self.orderTitle = label;
                self.orderMoney = desLabel;
            }else if (i == 1)
            {
                self.goodsIV = imageV;
                self.goodsTitle = label;
                self.goodsMoney = desLabel;
            }else
            {
                self.profitIV = imageV;
                self.profitTitle = label;
                self.profitMoney = desLabel;
            }
        }
    }
    if (!self.bottomIV) {
        self.bottomIV = [UIImageView new];
        self.bottomIV.image = [UIImage imageNamed:@"orderMoney"];
        self.bottomIV.hidden = YES;
        [self addSubview:self.bottomIV];
    }
    if (!self.bottomLab) {
        self.bottomLab = [UILabel new];
        self.bottomLab.textColor = titleColor;
        self.bottomLab.font = FontWithSize(12);
        self.bottomLab.text = @"订单总金额";
//        self.bottomLab.textAlignment = NSTextAlignmentRight;
        self.bottomLab.hidden = YES;
        [self addSubview:self.bottomLab];
    }
    if (!self.bottDesLab) {
        self.bottDesLab = [UILabel new];
        self.bottDesLab.textColor = titleColor;
        self.bottDesLab.font = FontWithSize(14);
        self.bottDesLab.text = @"¥320";
        self.bottDesLab.textAlignment = NSTextAlignmentRight;
        self.bottDesLab.hidden = YES;
        [self addSubview:self.bottDesLab];
    }
    if (!self.bottomV) {
        self.bottomV = [UIView new];
        self.bottomV.backgroundColor = UIColorFromHex(0xF7F7F7);
        self.bottomV.hidden = YES;
        [self addSubview:self.bottomV];
    }
}
//111
- (void)layoutSubviews
{
    [super layoutSubviews];
    float height = self.model.deliveryType == 3?0:65;
    self.addressView.frame = CGRectMake(0,0, self.width, height);
    self.addIV.frame = CGRectMake(15, (self.addressView.height-20)/2, 20, 20);
    
    CGFloat addWidth = self.width-60;
    NSString *content = self.model.consigneeDetailAddress;
    CGSize size = [TTKUtil sizeWithText:content Width:addWidth Font:FontMediumWithSize(12)];
    self.addressLab.frame = CGRectMake(self.addIV.right+10,(self.addressView.height-size.height)/2, addWidth, size.height);
    self.bottomView.frame = CGRectMake(0, self.addressView.bottom, self.width, 50);
    self.bottomV.frame = CGRectMake(0, self.height-10, self.width, 10);

    self.bottDesLab.frame = CGRectMake(self.width-75, self.addressView.bottom+18, 60, 14);
    self.bottomLab.frame = CGRectMake(self.bottDesLab.left-75, self.addressView.bottom+17, 60, 12);
    self.bottomIV.frame = CGRectMake(self.bottomLab.left-5-16, self.addressView.bottom+15, 16, 16);
}

- (void)getData:(OrderModel *)model
{
    self.model = model;
    self.addressLab.text = [NSString stringWithFormat:@"%@",model.consigneeDetailAddress];
    self.orderMoney.text = [NSString stringWithFormat:@"¥%.2f",model.orderAmount];
    self.goodsMoney.text = [NSString stringWithFormat:@"¥%.2f",model.costAmount];
    self.profitMoney.text = [NSString stringWithFormat:@"¥%.2f",model.gainAmount];
    self.bottDesLab.text = [NSString stringWithFormat:@"¥%.2f",model.orderAmount];
    
    //如果是状态3
    if (model.deliveryType == 3) {
        self.addressView.hidden = YES;
        self.addressLab.hidden = YES;
        self.addIV.hidden = YES;
        [self.addressView setSize:CGSizeMake(0, 0)];
    }else
    {
        self.addressView.hidden = NO;
        self.addressLab.hidden = NO;
        self.addIV.hidden = NO;
        self.addressView.height = 65;
    }
    
    if (model.showGainsInfo == NO) {
        self.orderIV.hidden = YES;
        self.orderTitle.hidden = YES;
        self.orderMoney.hidden = YES;
        self.goodsIV.hidden = YES;
        self.goodsTitle.hidden = YES;
        self.goodsMoney.hidden = YES;
        self.profitIV.hidden = YES;
        self.profitTitle.hidden = YES;
        self.profitMoney.hidden = YES;
        self.bottomIV.hidden = NO;
        self.bottomLab.hidden = NO;
        self.bottDesLab.hidden = NO;
    }
    else
    {
        self.orderIV.hidden = NO;
        self.orderTitle.hidden = NO;
        self.orderMoney.hidden = NO;
        self.goodsIV.hidden = NO;
        self.goodsTitle.hidden = NO;
        self.goodsMoney.hidden = NO;
        self.profitIV.hidden = NO;
        self.profitTitle.hidden = NO;
        self.profitMoney.hidden = NO;
        self.bottomIV.hidden = YES;
        self.bottomLab.hidden = YES;
        self.bottDesLab.hidden = YES;
    }
}

@end
